//
//  MoneyTabViewController.m
//  carcareIOS
//
//  Created by wr on 16/4/1.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MoneyTabViewController.h"

#import "MoneyStatisticsViewController.h"
#import "MoneyViewController.h"

typedef NS_ENUM(NSInteger , Segmented_Type)
{
    Segmented_Type_MoneyDetail = 60,//挣点明细
    Segmented_Type_MoneyStatisstics //挣点统计
};

@interface MoneyTabViewController ()

@property (nonatomic, strong) UISegmentedControl *segmentedControl;

@property (nonatomic, assign) NSInteger segmentType;//切换tab类型

@property (nonatomic , strong) MoneyStatisticsViewController * moneyStatisticsVC;

@property (nonatomic , strong) UIView * moneyStatisticsView;

@property (nonatomic , strong) MoneyViewController * moneyDetailVC;

@property (nonatomic , strong) UIView * moneyDetailView;

@end

@implementation MoneyTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"挣点明细",@"挣点统计"]];
    self.segmentedControl.frame = CGRectMake(0, 0, 224 * __MAIN_RATIO_375 , 23);
    [self.segmentedControl addTarget:self action:@selector(segmentedChange:) forControlEvents:UIControlEventValueChanged];
    self.segmentedControl.tintColor = [UIColor whiteColor];
    self.segmentedControl.selectedSegmentIndex = 0;
    self.segmentType = Segmented_Type_MoneyDetail;
    self.navigationItem.titleView = self.segmentedControl;
    
    [self createView];
    
}
- (void)createView
{
    self.moneyDetailVC = [[MoneyViewController alloc] initWithTableRefreshType:TYPE_TABLE_REFRESH_PULL_UP_DOWN];
    self.moneyDetailView = self.moneyDetailVC.view;
    [self.view addSubview:self.moneyDetailView];
    
    self.moneyStatisticsVC = [[MoneyStatisticsViewController alloc] initWithMainViewType:TYPE_MAIN_VIEW_SCROLL_NORMAL];
    self.moneyStatisticsView = self.moneyStatisticsVC.view;
    [self.view addSubview:self.moneyStatisticsView];
    
    [self reloadView];
}
- (void)segmentedChange:(UISegmentedControl *)segmented{
    switch (segmented.selectedSegmentIndex) {
        case 0:
            self.segmentType = Segmented_Type_MoneyDetail;
            [self.moneyDetailVC viewWillAppear:YES];
            break;
        case 1:
            self.segmentType = Segmented_Type_MoneyStatisstics;
            [self.moneyStatisticsVC viewWillAppear:YES];
            break;
            
        default:
            break;
    }
    [self reloadView];
    
}
- (void)reloadView
{
    [self.moneyDetailView setHidden:(self.segmentType == Segmented_Type_MoneyDetail ? NO : YES)];
    [self.moneyStatisticsView setHidden:(self.segmentType == Segmented_Type_MoneyStatisstics ? NO : YES)];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
